<template>
  <div class="approval_page">
    <div class="input_info">
      <el-form
        :model="form2"
        ref="formRef"
        :rules="rules"
        label-width="120px"
        label-position="right"
      >
        <el-form-item label="立项申请书:">
          <el-upload
            v-if="isDengNew"
            :action="uploadUrl"
            :on-success="handleSuccess"
            :headers="headers"
            :show-file-list="false"
          >
            <el-button
              icon="el-icon-plus"
              @click="clickBtn(1)"
              size="small"
              type="primary"
            >
              添加附件
            </el-button>
          </el-upload>

          <span v-if="form2.appendixUrl.length">
            <p v-for="(i, index) in form2.appendixUrl" :key="index">
              <span @click="openDoc(i)">{{ i.fileName }}</span>
              <i
                @click="onRemove(1, index)"
                v-if="isDengNew"
                class="el-icon-circle-close"
              ></i>
            </p>
          </span>
          <span v-if="!form2.appendixUrl.length && !isDengNew">暂无</span>
        </el-form-item>

        <el-form-item label="项目合同:">
          <el-upload
            v-if="isDengNew"
            :action="uploadUrl"
            :on-success="handleSuccess"
            :headers="headers"
            :show-file-list="false"
          >
            <el-button
              icon="el-icon-plus"
              @click="clickBtn(2)"
              size="small"
              type="primary"
            >
              添加附件
            </el-button>
          </el-upload>
          <span v-if="form2.xmProjectAppendix.contractAppendixUrl.length">
            <p
              v-for="(i, index) in form2.xmProjectAppendix.contractAppendixUrl"
              :key="index"
            >
              <span @click="openDoc(i)">
                {{ i.fileName }}
              </span>
              <i
                @click="onRemove(2, index)"
                v-if="isDengNew"
                class="el-icon-circle-close"
              ></i>
            </p>
          </span>
          <span
            v-if="
              !form2.xmProjectAppendix.contractAppendixUrl.length && !isDengNew
            "
          >
            暂无
          </span>
        </el-form-item>

        <el-form-item label="立项文件:">
          <el-upload
            v-if="isDengNew"
            :action="uploadUrl"
            :on-success="handleSuccess"
            :headers="headers"
            :show-file-list="false"
          >
            <el-button
              icon="el-icon-plus"
              @click="clickBtn(3)"
              size="small"
              type="primary"
            >
              添加附件
            </el-button>
          </el-upload>
          <span v-if="form2.xmProjectAppendix.setUpAppendixUrl.length">
            <p
              v-for="(i, index) in form2.xmProjectAppendix.setUpAppendixUrl"
              :key="index"
            >
              <span @click="openDoc(i)">
                {{ i.fileName }}
              </span>
              <i
                @click="onRemove(3, index)"
                v-if="isDengNew"
                class="el-icon-circle-close"
              ></i>
            </p>
          </span>
          <span
            v-if="
              !form2.xmProjectAppendix.setUpAppendixUrl.length && !isDengNew
            "
          >
            暂无
          </span>
        </el-form-item>

        <el-form-item label="项目实施计划:">
          <el-upload
            v-if="isDengNew"
            :action="uploadUrl"
            :on-success="handleSuccess"
            :headers="headers"
            :show-file-list="false"
          >
            <el-button
              icon="el-icon-plus"
              @click="clickBtn(4)"
              size="small"
              type="primary"
            >
              添加附件
            </el-button>
          </el-upload>
          <span
            v-if="form2.xmProjectAppendix.projectExecutionAppendixUrl.length"
          >
            <p
              v-for="(i, index) in form2.xmProjectAppendix
                .projectExecutionAppendixUrl"
              :key="index"
            >
              <span @click="openDoc(i)">
                {{ i.fileName }}
              </span>
              <i
                @click="onRemove(4, index)"
                v-if="isDengNew"
                class="el-icon-circle-close"
              ></i>
            </p>
          </span>
          <span
            v-if="
              !form2.xmProjectAppendix.projectExecutionAppendixUrl.length &&
              !isDengNew
            "
          >
            暂无
          </span>
        </el-form-item>

        <el-form-item label="通知文件:">
          <el-upload
            v-if="isDengNew"
            :action="uploadUrl"
            :on-success="handleSuccess"
            :headers="headers"
            :show-file-list="false"
          >
            <el-button
              icon="el-icon-plus"
              @click="clickBtn(5)"
              size="small"
              type="primary"
            >
              添加附件
            </el-button>
          </el-upload>
          <span v-if="form2.xmProjectAppendix.noticeAppendixUrl.length">
            <p
              v-for="(i, index) in form2.xmProjectAppendix.noticeAppendixUrl"
              :key="index"
            >
              <span @click="openDoc(i)">
                {{ i.fileName }}
              </span>
              <i
                @click="onRemove(5, index)"
                v-if="isDengNew"
                class="el-icon-circle-close"
              ></i>
            </p>
          </span>
          <span
            v-if="
              !form2.xmProjectAppendix.noticeAppendixUrl.length && !isDengNew
            "
          >
            暂无
          </span>
        </el-form-item>

        <el-form-item label="其他:">
          <el-upload
            v-if="isDengNew"
            :action="uploadUrl"
            :on-success="handleSuccess"
            :headers="headers"
            :show-file-list="false"
          >
            <el-button
              icon="el-icon-plus"
              @click="clickBtn(6)"
              size="small"
              type="primary"
            >
              添加附件
            </el-button>
          </el-upload>
          <span v-if="form2.xmProjectAppendix.otherAppendixUrl.length">
            <p
              v-for="(i, index) in form2.xmProjectAppendix.otherAppendixUrl"
              :key="index"
            >
              <span @click="openDoc(i)">
                {{ i.fileName }}
              </span>
              <i
                @click="onRemove(6, index)"
                v-if="isDengNew"
                class="el-icon-circle-close"
              ></i>
            </p>
          </span>
          <span
            v-if="
              !form2.xmProjectAppendix.otherAppendixUrl.length && !isDengNew
            "
          >
            暂无
          </span>
        </el-form-item>
      </el-form>
    </div>
    <div style="height: 16px; background: #f4f5fc"></div>
    <el-form
      style="width: 80%; margin: 0 auto"
      :model="form2"
      ref="formRef2"
      label-width="220px"
      label-position="top"
    >
      <el-form-item
        label="项目实施阶段"
        prop="xmProjectPeriodList"
        class="request_class"
      >
        <p class="subtitle">
          如：引进、筛选、培育、示范推广的林木新优品种，创新研发、试验熟化、集成示范推广的技术及预期对比效果，建设改进的设备生产线、示范基地及规模；制定技术规程、标准，申请、授权专利或植物新品种权，发表文章，撰写调研报告或决策咨询报告等。
        </p>
        <el-table
          :stripe="true"
          :data="form2.xmProjectPeriodList"
          style="width: 100%"
          :header-cell-style="{
            background: '#DDDDDD',
            color: '#333333',
          }"
        >
          <el-table-column type="index" label="序号" width="50" align="center">
            <template slot-scope="scope">
              {{ scope.row.index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="阶段" align="center">
            <template slot-scope="{ row }">
              <el-input
                v-model="row.periodName"
                @blur="jeiduanBlur(row)"
                placeholder="请输入"
                :disabled="!isDengNew || row.disabled"
              ></el-input>
              <span class="red_span" v-show="row.flag">阶段名称输入不正确</span>
            </template>
          </el-table-column>
          <el-table-column label="开始时间" align="center" width="200">
            <template slot-scope="scope">
              <el-date-picker
                style="width: 100%"
                v-model="scope.row.periodStartTime"
                type="datetime"
                :picker-options="{ format: 'yyyy-MM-dd HH:00' }"
                class="border_red"
                placeholder="请选择开始时间"
                @blur="startBlur(scope.row)"
                :disabled="!isDengNew"
              ></el-date-picker>
              <span class="red_span" v-show="scope.row.flag1">
                开始时间选择不正确
              </span>
            </template>
          </el-table-column>
          <el-table-column label="结束时间" align="center" width="200">
            <template slot-scope="scope">
              <el-date-picker
                style="width: 100%"
                v-model="scope.row.periodEndTime"
                type="datetime"
                :picker-options="{ format: 'yyyy-MM-dd HH:00' }"
                placeholder="请选择结束时间"
                :default-value="scope.row.periodStartTime"
                @blur="endBlur(scope.row)"
                :disabled="!isDengNew"
              ></el-date-picker>
              <span class="red_span" v-show="scope.row.flag2">
                结束时间选择不正确
              </span>
            </template>
          </el-table-column>
          <el-table-column
            width="140"
            align="center"
            fixed="right"
            v-if="isDengNew"
          >
            <template slot-scope="{ row }">
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-plus"
                @click="addPeriodList(row)"
              />
              <el-button
                v-if="!row.disabled"
                type="danger"
                size="mini"
                icon="el-icon-minus"
                @click="delPeriodList(row)"
              />
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
    </el-form>

    <div
      class="input_info contain"
      v-if="loginUser != '科研管理员' && isDengNew"
    >
      <div class="contain_btn">
        <el-button type="info" size="small" @click="saveProject('', '', 0)">
          取消
        </el-button>

        <el-button
          type="warning"
          size="small"
          @click="saveProject('formRef', 'formRef2', 1)"
        >
          暂存
        </el-button>
        <!-- 自立项目没有开启时,不能提交，只能暂存 -->
        <el-button
          type="primary"
          size="small"
          :disabled="!isStart"
          @click="saveProject('formRef', 'formRef2', 2)"
        >
          提交
        </el-button>
      </div>
    </div>
    <div class="input_info contain" v-if="loginUser != '科研管理员' && isLast">
      <el-button
        type="primary"
        size="small"
        @click="exportExcel"
        :loading="exportExcelLoading"
      >
        导出立项申报书
      </el-button>
      <el-button
        type="primary"
        size="small"
        @click="exportWord"
        :loading="exportWordLoading"
      >
        导出Word文档
      </el-button>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import { serverUrl } from "@/look";
import { Base64 } from "js-base64";

import { uploadUrl } from "@/const";
import { getToken } from "@/utils/auth";

import {
  apiSubmitAppendInfo, //补充-提交
  apitempAppendInfo, //补充-暂存
  apiExportFileWithText, //导出
} from "@/api2/projectManagement/examine";

import {
  exportAccessProjectWord, // 导出自立项目Word文档
} from "@/api2/projectManagement/reporting";

export default {
  props: {
    // 审批的时候不能填写
    isDisadled: {
      type: Boolean,
      default: false,
    },
    isStart: {
      type: Boolean,
      default: false,
    },
    loginUser: {
      type: String,
      default: "",
    },
    supplement: {
      type: Object,
      default: () => {},
    },
  },
  computed: {
    isDengNew() {
      return this.$store.state.project.projectInfo.isDengNew;
    },
    isLast() {
      return this.$store.getters.isLastSteps;
    },
  },
  data() {
    return {
      exportExcelLoading: false,
      exportWordLoading: false,
      clickIndex: 0,
      form2: {
        appendixUrl: [], //	申报书附件地址
        xmProjectAppendix: {
          setUpAppendixUrl: [], //	立项文件附件
          contractAppendixUrl: [], //项目合同附件
          projectExecutionAppendixUrl: [], //	项目实施计划附件
          noticeAppendixUrl: [], //	项目通知文件附件
          otherAppendixUrl: [], //	其他附件
        },

        // 项目实施阶段
        xmProjectPeriodList: [],
      },
      rules: {
        appendixUrl: [
          {
            required: true,
            message: "请选择立项申请书",
            trigger: "change",
          },
        ],
      },
      uploadUrl,
      headers: {
        Authorization: getToken(),
        platform: "WEB",
      },
    };
  },
  mounted() {
    this.init();
    const info = this.supplement;

    if (!this.isDengNew || info.appendixUrl) {
      // 立项申报书
      this.form2.appendixUrl =
        typeof info.appendixUrl == "string"
          ? JSON.parse(info.appendixUrl)
          : info.appendixUrl;

      // 合同文件
      this.form2.xmProjectAppendix.contractAppendixUrl =
        typeof info.xmProjectAppendix.contractAppendixUrl == "string"
          ? JSON.parse(info.xmProjectAppendix.contractAppendixUrl)
          : info.xmProjectAppendix.contractAppendixUrl;

      // 立项文件
      this.form2.xmProjectAppendix.setUpAppendixUrl =
        typeof info.xmProjectAppendix.setUpAppendixUrl == "string"
          ? JSON.parse(info.xmProjectAppendix.setUpAppendixUrl)
          : info.xmProjectAppendix.setUpAppendixUrl;

      // 项目实施计划
      this.form2.xmProjectAppendix.projectExecutionAppendixUrl =
        typeof info.xmProjectAppendix.projectExecutionAppendixUrl == "string"
          ? JSON.parse(info.xmProjectAppendix.projectExecutionAppendixUrl)
          : info.xmProjectAppendix.projectExecutionAppendixUrl;

      // 通知文件
      this.form2.xmProjectAppendix.noticeAppendixUrl =
        typeof info.xmProjectAppendix.noticeAppendixUrl == "string"
          ? JSON.parse(info.xmProjectAppendix.noticeAppendixUrl)
          : info.xmProjectAppendix.noticeAppendixUrl;

      // 其他
      this.form2.xmProjectAppendix.otherAppendixUrl =
        typeof info.xmProjectAppendix.otherAppendixUrl == "string"
          ? JSON.parse(info.xmProjectAppendix.otherAppendixUrl)
          : info.xmProjectAppendix.otherAppendixUrl;

      // 项目实施阶段
      for (let i = 0; i < info.xmProjectPeriodList.length; i++) {
        this.form2.xmProjectPeriodList[i] = {
          ...this.form2.xmProjectPeriodList[i],
          ...info.xmProjectPeriodList[i],
        };
      }
    }
  },
  methods: {
    // 计算合计
    getSummaries(param) {
      let data;
      if (param instanceof Array) {
        data = param;
      } else {
        data = param.data;
      }

      const sums = [];
      data.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        }
        const values = data.map((item) => Number(item.fundsAmount));

        if (index == 2) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += "万元";
        } else {
          sums[index] = "";
        }
      });
      return sums;
    },
    openDoc(e) {
      window.open(
        serverUrl +
          "onlinePreview?url=" +
          encodeURIComponent(Base64.encodeURI(e.url))
      );
    },
    init() {
      // 项目实施阶段
      this.form2.xmProjectPeriodList = [
        { index: 0, periodName: "项目实施方案", disabled: true },
        { index: 1, periodName: "中期检查", disabled: true },
        { index: 2, periodName: "结题验收", disabled: true },
        // {
        //   index: 0,
        //   periodName: "", //	实施阶段名称
        //   periodStartTime: "", //开始时间
        //   periodEndTime: "", // 结束时间,
        //   flag: false,
        //   flag1: false,
        //   flag2: false,
        // },
      ];
    },
    // 获取格式化时间字符串
    getFormatedTimeStr(stamp, str = "YYYY-MM-DD HH:mm") {
      return moment(stamp).format(str);
    },

    // 自立项目流程完成，导出
    exportExcel() {
      let id = this.$route.params.id;
      this.exportExcelLoading = true;
      apiExportFileWithText(id)
        .then((res) => {
          if (res.code === 0) {
            window.location.href = res.data.url;
          }
          this.exportExcelLoading = false;
        })
        .catch((err) => {
          console.log(err);
          this.exportExcelLoading = false;
        });
    },

    // 导出自立项目Word文档
    exportWord() {
      const exportWordInfo = JSON.parse(
        sessionStorage.getItem("exportWordInfo")
      );

      const {
        projectName,
        projectType,
        projectUnit,
        startTime,
        endTime,
        cooperateUnit,
        projectCategory,
        purpose,
        base,
        content,
        plan,
        target,
        conditionFirst,
        conditionSecond,
      } = { ...exportWordInfo };

      // 经费预算
      const xmProjectFundsList = exportWordInfo.funds.map((v, index) => {
        return {
          amount: v.amount,
          fundsAmount: v.fundsAmount,
          fundsEnumKey: v.fundsEnumKey,
          fundsEnumName: v.fundsEnumName,
          index: index + 1,
          name: v.name,
          note: v.note,
        };
      });

      const data = {
        projectName,
        projectType,
        projectUnit,
        startTime,
        endTime,
        cooperateUnit,
        projectCategory,
        purpose,
        base,
        content,
        plan,
        target,
        conditionFirst,
        conditionSecond,
        projectId: sessionStorage.getItem("clickProjectId"),
        specialistInfo: `${exportWordInfo.specialistInfo1},${exportWordInfo.specialistInfo2}`,
        contractAddress: `${exportWordInfo.contractAddress1},${exportWordInfo.contractAddress2}`,
        contractPhone: `${exportWordInfo.contractPhone1},${exportWordInfo.contractPhone2}`,
        xmProjectPersonList: exportWordInfo.user,
        xmProjectOtherPersonList: exportWordInfo.otherPerson,
        xmProjectFundsList,
      };
      this.exportWordLoading = true;
      exportAccessProjectWord(data)
        .then((res) => {
          if (res.code === 0) {
            window.location.href = res.data.url;
          }
          this.exportWordLoading = false;
        })
        .catch((err) => {
          console.log(err);
          this.exportWordLoading = false;
        });
    },

    // 阶段信息 - 添加
    addPeriodList(row) {
      if (!row.periodName || !row.periodStartTime || !row.periodEndTime) {
        this.msgError("请将信息完善后添加");
        return;
      }
      let myObject = {
        index: row.index + 1,
        periodName: "", //	实施阶段名称
        periodStartTime: "", //开始时间
        periodEndTime: "", // 结束时间,
        flag: false,
        flag1: false,
        flag2: false,
      };
      this.form2.xmProjectPeriodList.splice(row.index + 1, 0, myObject);
      for (let i = 0; i < this.form2.xmProjectPeriodList.length; i++) {
        this.form2.xmProjectPeriodList[i].index = i;
        this.form2.xmProjectPeriodList[i].sort = i;
      }
    },

    // 阶段信息 - 删除
    delPeriodList(row) {
      this.form2.xmProjectPeriodList.splice(row.index, 1);
      for (let i = 0; i < this.form2.xmProjectPeriodList.length; i++) {
        this.form2.xmProjectPeriodList[i].index = i;
        this.form2.xmProjectPeriodList[i].sort = i;
      }
    },

    // 失去焦点 1
    // 1 阶段
    jeiduanBlur(row) {
      row.flag = !row.periodName;
    },
    // 2 开始时间
    startBlur(row) {
      row.flag1 = !row.periodStartTime;
    },
    // 3 结束时间
    endBlur(row) {
      row.flag2 = !row.periodEndTime;
    },
    // 失去焦点 2
    clickBtn(e) {
      this.clickIndex = e;
    },

    // 移除
    onRemove(num, index) {
      let fileArr = [];
      if (num == 1) {
        fileArr = this.form2.appendixUrl;
      } else if (num == 2) {
        fileArr = this.form2.xmProjectAppendix.contractAppendixUrl;
      } else if (num == 3) {
        fileArr = this.form2.xmProjectAppendix.setUpAppendixUrl;
      } else if (num == 4) {
        fileArr = this.form2.xmProjectAppendix.projectExecutionAppendixUrl;
      } else if (num == 5) {
        fileArr = this.form2.xmProjectAppendix.noticeAppendixUrl;
      } else if (num == 6) {
        fileArr = this.form2.xmProjectAppendix.otherAppendixUrl;
      }

      fileArr.splice(index, 1);
    },

    // 文件上传成功
    handleSuccess(res) {
      let data = res.data;
      data.name = res.data.fileName;
      if (this.clickIndex == 1) {
        this.form2.appendixUrl.push(data);
      } else if (this.clickIndex == 2) {
        this.form2.xmProjectAppendix.contractAppendixUrl.push(data);
      } else if (this.clickIndex == 3) {
        this.form2.xmProjectAppendix.setUpAppendixUrl.push(data);
      } else if (this.clickIndex == 4) {
        this.form2.xmProjectAppendix.projectExecutionAppendixUrl.push(data);
      } else if (this.clickIndex == 5) {
        this.form2.xmProjectAppendix.noticeAppendixUrl.push(data);
      } else if (this.clickIndex == 6) {
        this.form2.xmProjectAppendix.otherAppendixUrl.push(data);
      }
    },

    // 取消
    reset() {
      this.form2 = {
        appendixUrl: [], //	申报书附件地址
        xmProjectAppendix: {
          setUpAppendixUrl: [], //	立项文件附件
          contractAppendixUrl: [], //项目合同附件
          projectExecutionAppendixUrl: [], //	项目实施计划附件
          noticeAppendixUrl: [], //	项目通知文件附件
          otherAppendixUrl: [], //	其他附件
        },

        // 项目实施阶段
        xmProjectPeriodList: [],
      };
      this.init();
    },

    saveProject(formName1, formName2, i) {
      let xPPL = this.form2.xmProjectPeriodList;

      for (let i = 0; i < xPPL.length; i++) {
        if (
          !xPPL[i].periodName ||
          !xPPL[i].periodStartTime ||
          !xPPL[i].periodEndTime
        ) {
          this.msgError("项目实施阶段信息填写不完整");
          return;
        }
      }

      let data = {
        projectId: this.$route.params.id,
        appendixUrl: [], //	申报书附件地址
        xmProjectAppendix: {
          setUpAppendixUrl: [], //	立项文件附件
          contractAppendixUrl: [], //项目合同附件
          projectExecutionAppendixUrl: [], //	项目实施计划附件
          noticeAppendixUrl: [], //	项目通知文件附件
          otherAppendixUrl: [], //	其他附件
        },

        // 项目实施阶段
        xmProjectPeriodList: [],
      };
      // 申报书附件地址
      data.appendixUrl = this.form2.appendixUrl.map((v) => {
        return {
          fileName: v.fileName,
          relativeFilePath: v.relativeFilePath,
          size: v.size,
          suffix: v.suffix,
          url: v.url,
        };
      });
      data.appendixUrl = JSON.stringify(data.appendixUrl);
      // 立项文件附件
      data.xmProjectAppendix.setUpAppendixUrl =
        this.form2.xmProjectAppendix.setUpAppendixUrl.map((v) => {
          return {
            fileName: v.fileName,
            relativeFilePath: v.relativeFilePath,
            size: v.size,
            suffix: v.suffix,
            url: v.url,
          };
        });
      data.xmProjectAppendix.setUpAppendixUrl = JSON.stringify(
        data.xmProjectAppendix.setUpAppendixUrl
      );
      // 项目合同附件
      data.xmProjectAppendix.contractAppendixUrl =
        this.form2.xmProjectAppendix.contractAppendixUrl.map((v) => {
          return {
            fileName: v.fileName,
            relativeFilePath: v.relativeFilePath,
            size: v.size,
            suffix: v.suffix,
            url: v.url,
          };
        });
      data.xmProjectAppendix.contractAppendixUrl = JSON.stringify(
        data.xmProjectAppendix.contractAppendixUrl
      );
      // 项目实施计划附件
      data.xmProjectAppendix.projectExecutionAppendixUrl =
        this.form2.xmProjectAppendix.projectExecutionAppendixUrl.map((v) => {
          return {
            fileName: v.fileName,
            relativeFilePath: v.relativeFilePath,
            size: v.size,
            suffix: v.suffix,
            url: v.url,
          };
        });
      data.xmProjectAppendix.projectExecutionAppendixUrl = JSON.stringify(
        data.xmProjectAppendix.projectExecutionAppendixUrl
      );
      // 项目通知文件附件
      data.xmProjectAppendix.noticeAppendixUrl =
        this.form2.xmProjectAppendix.noticeAppendixUrl.map((v) => {
          return {
            fileName: v.fileName,
            relativeFilePath: v.relativeFilePath,
            size: v.size,
            suffix: v.suffix,
            url: v.url,
          };
        });
      data.xmProjectAppendix.noticeAppendixUrl = JSON.stringify(
        data.xmProjectAppendix.noticeAppendixUrl
      );
      // 其他附件
      data.xmProjectAppendix.otherAppendixUrl =
        this.form2.xmProjectAppendix.otherAppendixUrl.map((v) => {
          return {
            fileName: v.fileName,
            relativeFilePath: v.relativeFilePath,
            size: v.size,
            suffix: v.suffix,
            url: v.url,
          };
        });
      data.xmProjectAppendix.otherAppendixUrl = JSON.stringify(
        data.xmProjectAppendix.otherAppendixUrl
      );

      // 项目实施阶段
      data.xmProjectPeriodList = this.form2.xmProjectPeriodList.map(
        (v, index) => {
          return {
            periodName: v.periodName, //	实施阶段名称
            periodStartTime: v.periodStartTime, //开始时间
            periodEndTime: v.periodEndTime, // 结束时间,
            sort: index + 1,
          };
        }
      );
      for (let i = 0; i < data.xmProjectPeriodList.length; i++) {
        // 开始时间
        data.xmProjectPeriodList[i].periodStartTime = this.getFormatedTimeStr(
          data.xmProjectPeriodList[i].periodStartTime
        );
        // 结束时间
        data.xmProjectPeriodList[i].periodEndTime = this.getFormatedTimeStr(
          data.xmProjectPeriodList[i].periodEndTime
        );
      }

      if (formName1 != 0 && formName2 != 0) {
        let form1 = false;
        let form2 = false;
        this.$refs[formName1].validate((valid1) => {
          form1 = valid1;
        });
        this.$refs[formName2].validate((valid2) => {
          form2 = valid2;
        });
        if (form1 && form2) {
          if (i == 1) {
            apitempAppendInfo(data)
              .then((res) => {
                if (res.code == 0) {
                  this.msgSuccess("暂存成功");
                  this.reset();
                } else {
                  this.msgError("暂存失败");
                }
              })
              .catch((err) => {
                console.log(err);
                this.msgError("暂存失败");
              });
          } else {
            apiSubmitAppendInfo(data)
              .then((res) => {
                if (res.code == 0) {
                  this.msgSuccess("提交成功");
                  this.reset();
                } else {
                  this.msgError("提交失败");
                }
              })
              .catch((err) => {
                console.log(err);
                this.msgError("提交失败");
              });
          }
        }
      } else {
        this.reset();
      }
    },
  },
};
</script>

<style lang="scss" scoped>
p {
  margin: 0;
  padding: 0;
}
::v-deep .el-table__cell {
  border: none !important;
}

// ::v-deep .el-input.is-disabled .el-input__inner {
//   background: #fff !important;
//   color: #606266 !important;
// }

::v-deep .el-textarea.is-disabled .el-textarea__inner {
  background-color: #f5f7fa !important;
  color: #606266 !important;
}

::v-deep .el-form--label-top .el-form-item__label {
  padding: 0;
}

::v-deep .border_red {
  position: relative;
}
.red_span {
  color: #ff0000;
  position: absolute;
  z-index: 100;
  bottom: -0.5rem;
  left: 1rem;
  font-size: 0.5rem;
}

.request_class::before {
  content: "*";
  color: #f56c6c;
  position: relative;
  top: 1.875rem;
  left: -0.625rem;
}

.approval_page {
  width: 100%;
  box-sizing: border-box;
  .input_info {
    padding: 1rem 0;
    width: 80% !important;
    margin: 0 auto;
  }
  .contain {
    .contain_info {
      .title {
        font-size: 1rem;
        color: #364a71;
        font-weight: bold;
        line-height: 1.1875rem;
      }
      .subtitle {
        // text-indent: 2em;
        background: red;
        font-size: 0.875rem;
        color: #333333;
        line-height: 1rem;
      }
      ::v-deep .last_head {
        background: transparent !important;
        border: transparent !important;
      }
    }
    .contain_btn {
      margin-top: 2.5rem;
      height: 2rem;
      width: 100%;
      text-align: center;
    }
  }
}
</style>
